home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / assocGen.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  597 b   |  24 lines

  1. //: C20:assocGen.h
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // The fill_n() and generate_n() equivalents 
  7. // for associative containers.
  8. #ifndef ASSOCGEN_H
  9. #define ASSOCGEN_H
  10.  
  11. template<class Assoc, class Count, class T>
  12. void 
  13. assocFill_n(Assoc& a, Count n, const T& val) {
  14.   for (; 0 < n; --n)
  15.     a.insert(val);
  16. }
  17.  
  18. template<class Assoc, class Count, class Gen>
  19. void assocGen_n(Assoc& a, Count n, Gen g) {
  20.   for (; 0 < n; --n)
  21.     a.insert(g());
  22. }
  23. #endif // ASSOCGEN_H ///:~
  24.